<!--
 * @title: 用户导入数据页
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-06-03 20:48:57
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-06-06 11:46:55
 * @version: 1.0.3
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
-->
<template>
  <ht-dialog title="导入列表数据" :visible.sync="isShow" @opened="handleFindImportUser">
    <ht-table v-show="isOpened" ref="importSuccessList" ref-table="importSuccessList" :table-head="importSuccessHead" :table-data="importSuccessData" table-type="import" />
    <template #footer>
      <ht-button type="primary" @click="handleConfirm">确 定</ht-button>
    </template>
  </ht-dialog>
</template>
<script>
import { sleep } from '@/utils';
import { findImportUsers } from '@/api/ht.admin';
export default {
  name: 'UserImport',
  props: {
    visible: {
      type: Boolean,
      required: false,
      default: false
    }
  },
  data() {
    return {
      isOpened: false,
      isShow: this.visible,
      dialogVisible: this.visible,
      importSuccessHead: [
        {
          label: '用户账号',
          prop: 'account'
        },
        {
          label: '用户姓名',
          prop: 'userName'
        }
      ],
      importSuccessData: {}
    };
  },
  watch: {
    isShow(newValue, oldValue) {
      sleep(200).then(() => {
        this.$emit('update:visible', newValue);
      });
    }
  },
  methods: {
    /**
     * @todo: 获取导入成功数据列表
     * @author: andy.ten@tom.com & xukaixing@hotmail.com
     * @Date: 2022-06-05 18:06:20
     */
    async handleFindImportUser() {
      this.isOpened = true;
      try {
        // fixme: 注意要使用@opened,否则this.$refs无法获取
        this.importSuccessData = await this.$crud.searchNoFm(this.$refs['importSuccessList'], findImportUsers, { createBy: 'admin' });
      } catch (e) {
        this.$notify.message(e, 'error');
      }
    },
    handleConfirm() {

    }
  }
};
</script>
